package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.entity.User;

/**
 * Created by yinyonggang on 2018/7/25.
 */
@RestController
@RequestMapping("feign")
public class FeignController {

    @Autowired
    private FeignInterfaceClient feignInterfaceClient;
    
    @RequestMapping("/first")
    public String getSentence() {
    	String getStr = feignInterfaceClient.getRequest();
    	System.out.println("--GET--i am the entry of calling.----");
    	
    	String postStr = feignInterfaceClient.postRequest();
    	
    	System.out.println("--POST--i am the entry of calling.----");
        return getStr + "---" + postStr;
    }
    
    @RequestMapping("/postParam")
    public String postParam(@RequestBody(required = false) User user) {
    	String postParam = feignInterfaceClient.postRequestByParam(user);
    	
        return postParam;
    }
    
    @RequestMapping("/requestParam")
    public int requestParam(@RequestParam(value = "pageNum") int pageNum) {
    	int postParam = feignInterfaceClient.requestParam(pageNum);
        return postParam;
    }
    
    /**
     * the method is not a feign request. is a simple POST request
     */
    @RequestMapping(value = "/getRandom", method = RequestMethod.POST)
    public int requestGet(@RequestBody String name) {
    	int num=(int)(Math.random()*100 + 100);
    	System.out.println("---random----" + num);
        return num;
    }
}
